package com.nestease.qa.dao.api

import com.nestease.qa.dao.entity.TestCase
import com.nestease.qa.dao.params.TestCaseQueryParams
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update
import org.apache.ibatis.annotations.UpdateProvider

/**
 * @author zoudongdong
 * @date 2018/3/3
 */
interface TestCaseDAO {

    @Select("""
            select ifnull(max(caseId),0)
            from LG_testcase
            """)
    public int getMaxTestCaseId();

    @Insert("""
            INSERT INTO `LG_testcase` (`caseId`, `teamId`, `projectId`, `url`, `requestType`, `headerKeys`, `headerValues`, `paramKeys`, `paramValues`, `paramRaw`, `jsonPathCheckPoint`, `creator`, `lastEditor`, `status`)
            VALUES(#{caseId},#{teamId} , #{projectId}, #{url}, #{requestType}, #{headerKeys}, #{headerValues}, #{paramKeys}, #{paramValues}, #{paramRaw},#{jsonPathCheckPoint}, #{creator}, #{lastEditor}, #{status});
            """)
    public void addTestCase(TestCase testCase);

    @Select("""
            select *
            from LG_testcase
            where caseId=#{caseId}
            """)
    public TestCase getTestCaseDetail(int caseId);

    @Select("""<script>
            select *
            from LG_testcase
            where 1=1
            <if test=\"status!=0\">
            and status=#{status}
            </if>
            <if test=\"teamId!=0\">
            and teamId=#{teamId}
            </if>
            <if test="projectId!=0">
            and projectId=#{projectId}
            </if>
            </script>""")
    public List<TestCase> getTestCaseInCondition(TestCaseQueryParams params);

    @Update("""
            update LG_testcase
            set teamId=#{teamId},projectId=#{projectId},url=#{url},
            headerKeys=#{headerKeys},headerValues=#{headerValues},
            paramKeys=#{paramKeys},paramValues=#{paramValues},
            paramRaw=#{paramRaw},jsonPathCheckPoint=#{jsonPathCheckPoint},
            lastEditor=#{lastEditor},requestType=#{requestType}
            where caseId=#{caseId}
            """)
    public void updateTestCase(TestCase testCase)

    @Update("""
            update LG_testcase
            set status=0,lastEditor=#{lastEditor}
            where caseId=#{caseId}
            """)
    public void deleteTestCase(TestCase testCase);
}
